<!-- <template>
  <div class="child">
    <h2>child---{{ msg }}</h2>
    <button @click="$emit('click', '子组件的数据')">setData</button>
  </div>
</template>
<script>
export default {
  // props: ['msg'],
  props: {
    msg: {
      type: String,
      default: '默认值'
    }
  },
  data() {
    return {}
  },
  setup(props) {
    console.log(props)
  }
}
</script>
<style lang="scss" scoped></style> -->

<template>
  <div class="child">
    <h2>child---{{ msg }}</h2>
    <button @click="setData">setData</button>
  </div>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue'
// 数组
// const props = defineProps(['msg'])
const props = defineProps({
  msg: {
    type: String,
    default: '默认值'
  }
})

// const emit = defineEmits(['click'])
// emit 校验
const emit = defineEmits({
  click(data) {
    if (data) {
      console.log('传递参数')
      return true
    } else {
      console.log('没有传递参数')
      return false
    }
  }
})
const setData = () => {
  emit('click')
  // emit('click', '子组件的数据')
}

console.log(props)
</script>

<style lang="scss" scoped></style>
